﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace DigitalQuran
{
    /// <summary>
    /// Global Constants
    /// </summary>
    public static class Globals
    {        
        /// <summary>
        /// Default TextMode
        /// </summary>
        public const string DefaultTextMode = "Simplified29";

        /// <summary>
        /// Default Values for Frequency used in WAV making
        /// </summary>
        public const int DefaultFrequency = 1433;

        /// <summary>
        /// Setup Global Values
        /// </summary>
        public static void Setup() {

            var args = Environment.GetCommandLineArgs();
            if (args.Length > 1) {
                Edition edition;
                if (Enum.TryParse<Edition>(args[1], out edition)) {
                    Edition = edition;
                }
            }

        }

        /// <summary>
        /// Edition of DigitalQuran
        /// </summary>
        public static Edition Edition { get; set; }
    }

    /// <summary>
    /// Common Directories used by Digital Qur'an
    /// </summary>
    public static class DigitalQuranDirectories
    {
        static DigitalQuranDirectories()
        {
            string appDirectory = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]) + "\\";

            string localDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Digital Quran\\";

            Data = appDirectory + "Data\\";

            Translation = appDirectory + "Translation\\";
            CreateDirectoryIfNotExist(Translation);

            SimplificationRules = appDirectory + "Rules\\";
            CreateDirectoryIfNotExist(SimplificationRules);

            Numbers = appDirectory + "Numbers\\";
            CreateDirectoryIfNotExist(Numbers);

            Numerology = appDirectory + "Values\\";
            NumerologyLocal = localDirectory + "Values\\";

            NumbersLocal = localDirectory + "Numbers\\";
            CreateDirectoryIfNotExist(NumbersLocal);

            TranslationLocal = localDirectory + "Translation\\";
            CreateDirectoryIfNotExist(TranslationLocal);

            Configurations = localDirectory + "Config\\";
            CreateDirectoryIfNotExist(Configurations);
        }

        /// <summary>
        /// Creates Directory if specified directory doesn't exist
        /// </summary>
        /// <param name="dir">Path of directory to check</param>
        static void CreateDirectoryIfNotExist(string dir)
        {
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
        }

        /// <summary>
        /// Data Directory : [Application Directory]\Data\
        /// </summary>
        public static string Data { get; private set; }

        /// <summary>
        /// Directory where user configuration files exist [AppLocalDataFolder]\Config\
        /// </summary>
        public static string Configurations { get; private set; }

        /// <summary>
        /// Directory where Translation Exits : [Application Directory]\Translation\
        /// </summary>
        public static string Translation { get; private set; }

        /// <summary>
        /// Directory where User-Speific Translation Files exist : [Application Directory]\Data\
        /// </summary>
        public static string TranslationLocal { get; private set; }

        /// <summary>
        /// Directory where Simplification Rules Files exits : [Application Directory]\Rules\
        /// </summary>
        public static string SimplificationRules { get; private set; }

        /// <summary>
        /// Directory where 
        /// </summary>
        public static string Numbers { get; private set; }
        public static string NumbersLocal { get; private set; }

        public static string Numerology { get; private set; }
        public static string NumerologyLocal { get; private set; }
    }

    /// <summary>
    /// Edition of DigitalQuran
    /// </summary>
    [Flags]
    public enum Edition : byte
    {
        /// <summary>
        /// Default Edition for all text modes including Simplified29Shadda.
        /// </summary>
        Standard = 0,

        /// <summary>
        /// for word-part by word-part grammar information.
        /// </summary>
        Grammar = 10,

        /// <summary>
        /// if your computer has less than 1Gb of RAM memory.
        /// </summary>
        Lite = 20,

        /// <summary>
        /// for many more numerology systems and many more research methods.
        /// </summary>
        Research = 30
    }
}